package com.bulletelc.apollopre.api;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.internal.bind.DateTypeAdapter;

import java.util.Date;

/**
 * author: lhl
 * date  : 2017/11/13
 * desc  : 生成单例的特定设置的gson对象
 */

class JsonConvertor {

    private static Gson gson = null;

    private JsonConvertor() {
        //empty
    }

    public static Gson getInstance() {
        if (gson == null) {
            synchronized (JsonConvertor.class) {
                if (gson == null) {
                    gson = new GsonBuilder()
                            .setPrettyPrinting()
                            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                            .registerTypeAdapter(Date.class, new DateTypeAdapter())
                            .create();
                }
            }

        }
        return gson;
    }
}
